package com.atguigu.boot;

import com.atguigu.boot.bean.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/*主程序类
@SpringBootApplication:这是一个Springboot应用
相当于3个注解
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.atguigu.boot")
*/
@SpringBootApplication//默认扫描同级及其子孙集包类@SpringBootApplication(scanBasePackages = "com.atguigu.boot")
public class MainApplication {
    public static void main(String[] args) {

        //1.返回我们的IOC容器
        ConfigurableApplicationContext run = SpringApplication.run(MainApplication.class, args);
        //2.查看容器里的组件
        String[] names = run.getBeanDefinitionNames();
        for (String name:names){
            System.out.println(name);
        }
        //3.从容器中获取组件,默认也是单实例的
        Object user01 = run.getBean("user01", User.class);
        Object user02 = run.getBean("user01",User.class);
        System.out.println("是否单实例:"+(user01==user02));


    }
}
